package com.whccb.apps.office.document.event;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListener;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;

public class ModifyStatusAfterHgTaskEvent extends ExecuteListener {
	public String getDescription() {
		return "公文发文流程核稿节点，更新流程状态。";
	}

	public String getProvider() {
		return "ActionSoft";
	}

	public String getVersion() {
		return "AWS 6.0";
	}

	public void execute(ProcessExecutionContext pec) throws Exception {
		String bindid = pec.getProcessInstance().getId();
		String boName = "";
		Map<String, Object> paramMap = SDK.getProcessAPI().getVariables(bindid);
		
		if (paramMap != null && !paramMap.isEmpty()) {
			boName = paramMap.get("BONAME") != null ? paramMap.get("BONAME")
					.toString() : "";
		}
		String taskStatus = "";
		if (pec.isChoiceActionMenu("行领导签发")) {
			SDK.getProcessAPI().setVariable(pec.getProcessInstance(), "HgTaskChoiceAction","行领导签发");
		} else {
			SDK.getProcessAPI().setVariable(pec.getProcessInstance(), "HgTaskChoiceAction","非行领导签发");
		}
		if (pec.isChoiceActionMenu("分管领导签发") || pec.isChoiceActionMenu("行领导签发")) {
			taskStatus = "已核稿";
		}
		if (pec.isChoiceActionMenu("文书岗套红印发")) {
			taskStatus = "已签发";
		}
		if (StringUtils.isNotEmpty(boName)
				&& StringUtils.isNotEmpty(taskStatus)) {
			String updateSql = " UPDATE " + boName
					+ " SET STATUS = :STATUS WHERE BINDID =:BINDID ";
			Map<String, Object> updateParam = new HashMap<String, Object>();
			updateParam.put("STATUS", taskStatus);
			updateParam.put("BINDID", bindid);
			DBSql.update(updateSql, updateParam);
		}

	}
}
